/*==============================================================================
 * AUTH: Matthew Baum, 9753095
 * 		Domenico Romano 5574331
 * DATE: January-27-2012
 * DESC: Java class to hold Task data.
 *==============================================================================*/

package Phase_1;

import org.w3c.dom.*;

public class Task {

    private int ID, duration;
    private String title, assignee;

    // Constructor
    public Task(int id, int dur, String title, String assgn)
    {
        ID = id;
        duration = dur;
        this.title = title;
        assignee = assgn;
    }
    

	public int getID() {
		return ID;
	}

	

	public int getDuration() {
		return duration;
	}

	

	public String getTitle() {
		return title;
	}

	

	public String getAssignee() {
		return assignee;
	}

	public 
	

	// Static method to create a Task from an XML DOM node:
    static Task getTaskFromXMLNode(Node task)
    {
        // Variables to init a task object:
        int ID = 0, duration = 0;
        String title = "", assignee = "";

        // Get the task attributes (ID AND duration)
        NamedNodeMap taskAttributes = task.getAttributes();

        // Get the child nodes (title AND assignee)
        NodeList taskContents = task.getChildNodes();

        // Get the task ID:
        ID = Integer.parseInt( taskAttributes.getNamedItem("ID").getNodeValue() );

        // Get the duration:
        duration = Integer.parseInt( taskAttributes.getNamedItem("duration").getNodeValue() );

        // Iterate over the child nodes
        for(int j = 0; j != taskContents.getLength(); ++j)
        {
            // Identify the node label
            String label = taskContents.item(j).getNodeName();

            // Set task title
            if( label.equals("title") )
            {
                title = taskContents.item(j).getTextContent();
            }
                    
            // Set task assignee
            else if( label.equals("assignee") )
            {
                assignee = taskContents.item(j).getTextContent();
            }
        }

        // Return Task object created from the values extracted from the XML DOM node
        return( new Task(ID, duration, title, assignee) );
    }
    
    

    // ToString
    @Override
    public String toString()
    {
        return("TASK #" + ID + ": " + title + ".\tDuration: " + duration + ".\tAssigned to: " + assignee);
    }
}
